<template>
  <div>
    <el-row :gutter="12">
      <el-col :span="12">
        <el-card shadow="always">
          <div slot="header">
            <span> <i class="el-icon-user"></i>教师总人数</span>
            <el-button style="float: right; padding: 3px 0" type="text">详情</el-button>
            <!-- <router-link to="/teable/index">
              
            </router-link> -->

          </div>
          <h1>{{ teachernum }}</h1>
        </el-card>
      </el-col>
      <el-col :span="12">
        <el-card shadow="always">
          <div slot="header">
            <span> <i class="el-icon-price-tag"></i>学生总人数</span>
            <el-button style="float: right; padding: 3px 0" type="text">详情</el-button>
            <!-- <router-link to="/student/student">
              
            </router-link> -->

          </div>
          <h1>{{ stunum }}</h1>
        </el-card>
      </el-col>
    </el-row>

    <el-row :gutter="12" style="margin-top: 16px">
      <el-col :span="12">
        <!-- background: #DCDFE6" -->
        <div id="teacher" style="float:left;width:100%;height: 300px; background:transparent;"></div>
      </el-col>
      <el-col :span="12">
        <div id="student" style="float:left;width:100%;height: 300px; background:transparent;"></div>
      </el-col>
    </el-row>



  </div>
</template>
<script>
import usersApi from '@/api/users'
import teacherApi from '@/api/tacher'
import Axios from 'axios';
import * as echarts from 'echarts'
import { rmSync } from 'fs';
export default {
  data() {
    return {
      teachercount: '',
      studentcount: '',
      tt1: '',
      stunum: '',
      teachernum: '',
    }
  },
  name: 'Echarts',
  methods: {
    getstu() {
      usersApi.getstucount().then(response => {
        this.stunum = response.data.stunum;
      })
    },
    gettea() {
      teacherApi.getteachercount().then(response => {
        this.teachernum = response.data.teachernum;
      })
    },
    myEcharts() {
      // 基于准备好的dom，初始化echarts实例
      var myChart = this.$echarts.init(document.getElementById('student'));

      // 指定图表的配置项和数据
      var option = {
        tooltip: {
          trigger: 'item'
        },
        legend: {
          top: '5%',
          left: 'center'
        },
        series: [
          {
            // name: 'Access From',
            type: 'pie',
            radius: ['40%', '70%'],
            avoidLabelOverlap: false,
            itemStyle: {
              borderRadius: 10,
              borderColor: '#fff',
              borderWidth: 2
            },
            label: {
              show: false,
              position: 'center'
            },
            emphasis: {
              label: {
                show: true,
                fontSize: 40,
                fontWeight: 'bold'
              }
            },
            labelLine: {
              show: false
            },
            data: [

            ]
          }
        ]
      };
      var myChart1 = this.$echarts.init(document.getElementById('teacher'));

      var teacher = {
        title: {
          // text: 'Referer of a Website',
          // subtext: 'Fake Data',
          left: 'center'
        },
        tooltip: {
          trigger: 'item'
        },
        legend: {
          orient: 'vertical',
          left: 'left'
        },
        series: [
          {
            // name: 'Access From',
            type: 'pie',
            radius: '50%',
            data: [
            ],
            emphasis: {
              itemStyle: {
                shadowBlur: 10,
                shadowOffsetX: 0,
                shadowColor: 'rgba(0, 0, 0, 0.5)'
              }
            }
          }
        ]
      };

      // 使用刚指定的配置项和数据显示图表。


      fetch("http://localhost:9001/system/student/count/student").then(response => response.json()).then(res => {
        res.forEach(item => {
          option.series[0].data.push({ value: item.num, name: item.className, })
          // option.data =data

        });
        this.studentcount = option.series[0].data;

        myChart.setOption(option);
      }),

        fetch("http://localhost:9001/teacher/count/teacher").then(response => response.json()).then(res => {
          res.forEach(item => {
            teacher.series[0].data.push({ value: item.num, name: item.zhicheng, })
            // option.data =data
            // console.log(item.value)
          });
          console.log("ceshi " + teacher.series[0].data[0].value);




          this.teachercount = teacher.series[0].data.length;

          myChart1.setOption(teacher);
        })

    }
  },
  mounted() {
    this.myEcharts();
    this.getstu();
    this.gettea();
    
  }
}


</script>

<style scoped></style>

